import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:recipe/module/globalColor.dart';

class Search extends StatefulWidget {
  final clickGetFoodList;
  Search({Key key, @required this.clickGetFoodList}) : super(key: key);
  @override
  _SearchState createState() => _SearchState();
}

class _SearchState extends State<Search> {
  String searchVal = "";
  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: new BoxDecoration(
        border: Border.all(color: Colors.white, width: 1.0), //灰色的一层边框
        color: Colors.white,
        borderRadius: BorderRadius.all(Radius.circular(5.0)),
      ),
      alignment: Alignment.center,
      height: 38,
      padding: EdgeInsets.only(left: 15, right: 15),
      child: Row(
        mainAxisSize: MainAxisSize.min,
        children: [
          Expanded(
              child: TextField(
            onChanged: (text) {
              //内容改变的回调
              searchVal = text;
            },
            onSubmitted: (val) => {widget.clickGetFoodList(1, 0, 'hot', val)},
            decoration: InputDecoration(
                contentPadding: EdgeInsets.all(10.0),
                border: OutlineInputBorder(
                  borderSide: BorderSide(
                    color: GlobalColor.themeColor, // 边框颜色
                  ),
                ),
                enabledBorder: OutlineInputBorder(
                  borderSide: BorderSide(
                    color: GlobalColor.themeColor, // 边框颜色
                  ),
                ),
                hintText: '搜菜谱~'),
          )),
          Container(
              width: 80,
              child: Center(
                  child: new MaterialButton(
                // color: GlobalColor.themeColor,
                color: GlobalColor.themeColor,
                textColor: Colors.white,
                child: new Text('搜索'),
                shape: RoundedRectangleBorder(
                    side: BorderSide.none,
                    borderRadius: BorderRadius.only(
                        topRight: Radius.circular(50),
                        bottomRight: Radius.circular(50))),

                onPressed: () {
                  widget.clickGetFoodList(1, 0, 'hot', searchVal);
                },
              )))
        ],
      ),
    );
  }
}
